package contacts.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import contacts.dao.IContactsDao;
import contacts.db.DbConnection;
import contacts.po.Room;
import contacts.po.Student;

public class RoomDaoImpl implements IContactsDao {

	/**
	 * 返回对应宿舍号的主键
	 */
	@Override
	public int getRoomId(Room room) {
		Connection conn = null;
		ResultSet rs = null;
		PreparedStatement ps = null;
		int roomId = 0;
		conn = DbConnection.getConnection();
		String sql = "select * from room where room_No = ?";
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, room.getRoomNo());
			rs = ps.executeQuery();
			while (rs.next()) {
				roomId = rs.getInt(1);
			}
		} catch (SQLException e) {
			System.out.println("Jdbc程序发生错误：" + e);
		} finally {
			DbConnection.close(ps, rs);
		}
		return roomId;
	}

	/**
	 * 返回对应主键的宿舍号
	 */
	@Override
	public String getRoomNo(Room room) {
		Connection conn = null;
		ResultSet rs = null;
		PreparedStatement ps = null;
		String roomNo = null;
		conn = DbConnection.getConnection();
		String sql = "select * from room where room_id = ?";
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, room.getRoomId());
			rs = ps.executeQuery();
			while (rs.next()) {
				roomNo = rs.getString(2);
			}
		} catch (SQLException e) {
			System.out.println("Jdbc程序发生错误：" + e);
		} finally {
			DbConnection.close(ps, rs);
		}
		return roomNo;
	}

	@Override
	public void save(Student student) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Student student) {
		// TODO Auto-generated method stub

	}

	@Override
	public Student get(String studentId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void delete(String studentId) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<Student> findAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getMessage(Student student, int i) {
		// TODO Auto-generated method stub
		return null;
	}

}
